import { BasicColumn, FormSchema } from '@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import { ywUserSelectList } from '@/api/heng/ywManage';
import { ApiSelect } from '@/components/Form';
import util from '@/utils/util';
import { useMessage } from '@/hooks/web/useMessage';
import { VxeFormItemProps, VxeGridPropTypes } from '@/components/VxeTable';

export function openModal(record) {
  console.log('--record ', record);
}

type CheckedType = boolean | string | number;
// BasicColumn[]

// VxeColumnPropTypes.CellRender

export const vxeTableFormSchema: VxeFormItemProps[] = [
  {
    span: 5,
    field: 'orderNoLike',
    title: '查询',
    itemRender: {
      props: {
        placeholder: '来源单据编号',
      },
      name: 'AInput',
    },
  },
  // {
  //   span: 5,
  //   field: 'state0',
  //   title: 'ms审批状态',
  //   itemRender: {
  //     name: 'ASelect',
  //     defaultValue: 9999,
  //     props: {
  //       options: [
  //         { label: '已审批', value: 9999 },
  //         { label: '审批中', value: 0 },
  //         { label: '需修改', value: -1 },
  //       ],
  //       style: { width: '100%' },
  //     },
  //   },
  // },
  {
    span: 5,
    field: 'xiaoShouDingDanTIDLike',
    title: '销售单号',
    itemRender: {
      props: {
        placeholder: '请输入销售单号',
      },
      name: 'AInput',
    },
  },

  // {
  //   span: 5,
  //   field: 'userNameLogin',
  //   title: '模拟登录人员',
  //   itemRender: {
  //     props: {
  //       placeholder: '人员名称',
  //     },
  //     name: 'AInput',
  //   },
  // },
  {
    span: 5,
    field: 'dateArr',
    title: '收款日期区间',
    itemRender: {
      props: {
        valueFormat: 'YYYY-MM-DD',
        format: 'YYYY-MM-DD',
      },
      name: 'ARangePicker',
    },
  },
  {
    span: 5,
    itemRender: {
      name: 'VxeButtonGroup',
      options: [
        { type: 'reset', content: '重置' },
        { type: 'submit', content: '查询', status: 'primary' },
      ],
    },
  },
];

export const rules = {
  mouldNameObj: [{ required: true, message: '费用名称不能为空', trigger: 'change' }],
  materialNo: [
    { required: true, message: '物料编号不能为空', trigger: 'change' },
    { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
  orderNo: [
    { required: true, message: '采购单号不能为空', trigger: 'change' },
    { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
};

/**
 * 确认提交审批列表
 */

export const confirmColumns: VxeGridPropTypes.Columns = [
  {
    title: '单据来源编号',
    field: 'orderNo',
    showOverflow: 'title',
    width: 130,
  },
  {
    title: '类型',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },

  {
    title: '金额(人民币)',
    field: 'totalAllPrice',
    showOverflow: 'title',
    slots: {
      footer: 'footer_totalAllPrice',
    },
    width: 100,
  },
  {
    title: '订单抽成金额',
    field: 'orderCommissionPrice0',
    slots: {
      footer: 'footer_orderCommissionPrice',
    },
    showOverflow: 'title',
    width: 100,
  },
  {
    title: '部门',
    field: 'salesmanDeptName0',
    align: 'center',
    width: 80,
  },
  {
    title: '接单人',
    field: 'receiverUserName0',
    align: 'center',
    width: 60,
  },
  {
    title: '接单人抽成金额',
    field: 'receiverUserPrice0',
    slots: {
      footer: 'footer_receiverUserPrice',
    },
    align: 'center',
    width: 60,
  },

  {
    title: '跟单人',
    field: 'merchandiserUserName0',
    align: 'center',
    width: 60,
  },
  {
    title: '跟单人抽成金额',
    field: 'merchandiserUserPrice0',
    slots: {
      footer: 'footer_merchandiserUserPrice',
    },
    align: 'center',
    width: 60,
  },
  {
    title: '介绍人',
    field: 'introduceUserName',
    // filters: [{ data: '' }],
    // filterRender: {
    //   name: 'VxeInput',
    // },
    align: 'center',
    width: 60,
  },
  {
    title: '介绍人抽成',
    field: 'introduceUserPrice',
    align: 'center',
    width: 60,
    slots: {
      footer: 'footer_introduceUserPrice',
    },
  },
  {
    title: '业务经理',
    field: 'manageUserName0',
    align: 'center',
    width: 70,
  },
  {
    title: '经理抽成',
    field: 'manageUserPrice0',
    slots: {
      footer: 'footer_manageUserPrice',
    },
    align: 'center',
    width: 90,
  },
  {
    title: '项目组',
    field: 'xiangMuGroupName0',
    align: 'center',
    width: 70,
  },
  {
    title: '项目组抽成',
    field: 'xiangMuGroupPrice0',
    slots: {
      footer: 'footer_xiangMuGroupPrice',
    },
    align: 'center',
    width: 90,
  },
  {
    width: 80,
    title: '操作',
    align: 'center',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

/**
 * 确认提交审批列表 k3
 */

export const k3Columns: VxeGridPropTypes.Columns = [
  {
    title: '回款日期',
    field: '回款日期',
    showOverflow: 'title',
  },
  {
    title: '客户名称',
    field: '客户名称',
    showOverflow: 'title',
    align: 'center',
  },

  {
    title: '回款金额',
    field: '回款金额',
    showOverflow: 'title',
    slots: {
      footer: 'footer_totalAllPrice',
    },
  },
  {
    title: '姓名',
    field: '姓名',
    showOverflow: 'title',
  },

  // {
  //   width: 80,
  //   title: '操作',
  //   align: 'center',
  //   slots: { default: 'action' },
  //   fixed: 'right',
  // },
];

/**
 * 发票核销明细列
 */

export const fapiaoColumns: VxeGridPropTypes.Columns = [
  {
    type: 'checkbox',
    title: '',
    field: 'seq',
    width: 40,
  },
  {
    title: 'oid',
    field: 'oid',
    showOverflow: 'title',
    width: 50,
  },
  {
    title: '收款/预收编号',
    field: 'skqrNo',
    showOverflow: 'title',
    width: 130,
    filters: [{ data: '' }], // 过滤器
    filterRender: {
      name: 'VxeInput',
    },
  },
  {
    title: '销售单号',
    field: 'xiaoShouDingDanTID',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '发票编号',
    field: 'zhuTID',
    showOverflow: 'title',
    filters: [{ data: '' }], // 过滤器
    filterRender: {
      name: 'VxeInput',
    },
    align: 'center',
    width: 130,
  },
  {
    title: '物料编号',
    field: 'wuLiaoBianHao',
    showOverflow: 'title',
    align: 'center',
    filters: [{ data: '' }], // 过滤器
    filterRender: {
      name: 'VxeInput',
    },
    width: 100,
  },

  {
    title: '物料名称',
    field: 'wuLiaoMingCheng',
    showOverflow: 'title',
    filters: [{ data: '' }], // 过滤器
    filterRender: {
      name: 'VxeInput',
    },
    align: 'center',
    width: 100,
  },
  {
    title: '物料型号',
    field: 'xingHao',
    showOverflow: 'title',
    filters: [{ data: '' }], // 过滤器
    filterRender: {
      name: 'VxeInput',
    },
    align: 'center',
    width: 100,
  },
  {
    title: '是否核算完成',
    field: 'heSuanWanCheng',
    showOverflow: 'title',
    align: 'center',
    formatter: ({ cellValue }) => {
      return cellValue == 1 ? '是' : '否';
    },
    width: 100,
    filters: [
      { label: '是', value: 1 },
      { label: '否', value: 0 },
    ],
  },
  // {
  //   title: '销售订单号',
  //   field: 'xiaoShouDingDanTID',
  //   showOverflow: 'title',
  //   align: 'center',
  //   width: 100,
  // },
  {
    title: '开票金额',
    field: 'duiZhangJinE',
    showOverflow: 'title',
    align: 'center',
    width: 100,
    slots: {
      footer: 'footer_duiZhangJinE',
    },
  },
  {
    title: '开票人民币金额',
    field: 'duiZhangRenMinBiJinE',
    showOverflow: 'title',
    align: 'center',
    width: 100,
    slots: {
      footer: 'footer_duiZhangRenMinBiJinE',
    },
  },
  {
    title: '确认到货金额',
    field: 'queRenDaoHuoJinE',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '确认到货人民币金额',
    field: 'queRenDaoHuoRenMinBiJinE',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '来源单据类型',
    field: 'laiYuanDanJuLeiXing',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '领用性质',
    field: 'lingYongXingZhi',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    width: 80,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
  },
];

export function fapiaoTotalCountFn(list) {
  let totalObj = { duiZhangRenMinBiJinE: 0, duiZhangJinE: 0 };
  let duiZhangRenMinBiJinE = 0,
    duiZhangJinE = 0;
  for (let i in list) {
    let item = list[i];
    if (item.duiZhangRenMinBiJinE) {
      duiZhangRenMinBiJinE = duiZhangRenMinBiJinE + item.duiZhangRenMinBiJinE;
    }
    if (item.duiZhangJinE) {
      duiZhangJinE = duiZhangJinE + item.duiZhangJinE;
    }
  }
  totalObj.duiZhangRenMinBiJinE = duiZhangRenMinBiJinE.toFixed(2);
  totalObj.duiZhangJinE = duiZhangJinE.toFixed(2);
  return totalObj;
}

/**
 * 期初列
 */

export const qichuColumns: VxeGridPropTypes.Columns = [
  {
    type: 'checkbox',
    title: '',
    field: 'seq',
    width: 40,
  },
  {
    title: 'oid',
    field: 'oid',
    showOverflow: 'title',
    width: 50,
  },
  {
    title: '收款确认编号',
    field: 'zhuTID',
    showOverflow: 'title',
    width: 130,
    filters: [{ data: '' }], // 过滤器
    filterRender: {
      name: 'VxeInput',
    },
  },
  {
    title: '汇率',
    field: 'huiLv',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '发票编号',
    field: 'faPiaoHao',
    showOverflow: 'title',
    filters: [{ data: '' }], // 过滤器
    filterRender: {
      name: 'VxeInput',
    },
    align: 'center',
    width: 130,
  },
  {
    title: '来源单据类型',
    field: 'laiYuanDanJuLeiXing',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '应收总金额(人民币)',
    field: 'yingShouFaPiaoHeXiaoRenMinBiZongJinE',
    showOverflow: 'title',
    align: 'center',

    width: 100,
  },

  {
    title: '实际收款人民币',
    field: 'shiJiShouKuanRenMinBiJinE',
    showOverflow: 'title',
    align: 'center',
    width: 100,
    slots: {
      //  footer: 'footer_duiZhangJinE',
    },
  },
  {
    title: '应收款日期',
    field: 'yingShouKuanRiQi',
    showOverflow: 'title',
    align: 'center',
    width: 100,
    formatter: ({ cellValue, row, column }) =>
      `${cellValue ? util.formatDate(new Date(cellValue)) : ''}`,
  },
  {
    title: '折扣(原币)',
    field: 'jieSuanZheKouJinE',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '手续费(原币)',
    field: 'shouXuFei',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },

  {
    width: 80,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
  },
];

/**
 * 预收款明细列
 */

export const yuhsouColumns: VxeGridPropTypes.Columns = [
  {
    title: '预收款编号',
    field: 'skqrNo',
    showOverflow: 'title',
    width: 130,
  },
  {
    title: '物料编号',
    field: 'wuLiaoBianHao',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },

  {
    title: '物料名称',
    field: 'wuLiaoMingCheng',
    showOverflow: 'title',
    align: 'center',
    width: 200,
  },
  {
    title: '物料型号',
    field: 'xingHao',
    showOverflow: 'title',
    align: 'center',
    width: 200,
  },
  {
    title: '性质',
    field: 'lingYongXingZhi',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '销售订单号',
    field: 'xiaoShouDingDanTID',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },

  {
    title: '确认到货金额',
    field: 'queRenDaoHuoJinE',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
  {
    title: '确认到货人民币金额',
    field: 'queRenDaoHuoRenMinBiJinE',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },
];

/**
 * 导出excel 列
 */
// export const exportColumns: VxeGridPropTypes.Columns = [
//   {
//     title: '发票编号',
//     field: 'zhuTID',
//     showOverflow: 'title',
//     width: 130,
//   },
//   {
//     title: '物料编号',
//     field: 'wuLiaoBianHao',
//     showOverflow: 'title',
//     align: 'center',
//     width: 100,
//   },
//
//   {
//     title: '物料名称',
//     field: 'wuLiaoMingCheng',
//     showOverflow: 'title',
//     align: 'center',
//     width: 100,
//   },
//   {
//     title: '来源单据类型',
//     field: 'laiYuanDanJuLeiXing',
//     showOverflow: 'title',
//     align: 'center',
//     width: 100,
//   },
//   // {
//   //   title: '领用性质',
//   //   field: 'lingYongXingZhi',
//   //   showOverflow: 'title',
//   //   align: 'center',
//   //   width: 100,
//   // },
//   {
//     title: '销售订单号',
//     field: 'xiaoShouDingDanTID',
//     showOverflow: 'title',
//     align: 'center',
//     width: 100,
//   },
//
//   {
//     title: '确认到货金额',
//     field: 'queRenDaoHuoJinE',
//     showOverflow: 'title',
//     align: 'center',
//     width: 100,
//   },
//
//   {
//     title: '确认到货人民币金额',
//     field: 'queRenDaoHuoRenMinBiJinE',
//     showOverflow: 'title',
//     align: 'center',
//     width: 100,
//   },
// ];

export const addExcludeColumns: VxeGridPropTypes.Columns = [
  {
    title: '单据来源编号',
    field: 'orderNo',
    showOverflow: 'title',
    width: 130,
  },
  {
    title: '类型',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },

  {
    title: '金额(人民币)',
    field: 'totalAllPrice',
    showOverflow: 'title',
    slots: {
      footer: 'footer_totalAllPrice',
    },
    width: 100,
  },
  {
    title: '订单抽成金额',
    field: 'orderCommissionPrice0',
    slots: {
      footer: 'footer_orderCommissionPrice',
    },
    showOverflow: 'title',
    width: 100,
  },

  {
    title: '接单人',
    field: 'receiverUserName0',
    align: 'center',
    width: 100,
  },
  {
    title: '接单人抽成金额',
    field: 'receiverUserPrice0',
    slots: {
      footer: 'footer_receiverUserPrice',
    },
    align: 'center',
    width: 100,
  },

  {
    title: '跟单人',
    field: 'merchandiserUserName0',
    align: 'center',
    width: 100,
  },
  {
    title: '跟单人抽成金额',
    field: 'merchandiserUserPrice0',
    slots: {
      footer: 'footer_merchandiserUserPrice',
    },
    align: 'center',
    width: 100,
  },

  {
    title: '业务经理',
    field: 'manageUserName0',
    align: 'center',
    width: 70,
  },
  {
    title: '经理抽成',
    field: 'manageUserPrice0',
    slots: {
      footer: 'footer_manageUserPrice',
    },
    align: 'center',
    width: 90,
  },
  {
    title: '项目组',
    field: 'xiangMuGroupName0',
    align: 'center',
    width: 70,
  },
  {
    title: '项目组抽成',
    field: 'xiangMuGroupPrice0',
    slots: {
      footer: 'footer_xiangMuGroupPrice',
    },
    align: 'center',
    width: 90,
  },
  {
    width: 80,
    title: '操作',
    align: 'center',
    slots: { default: 'action' },
    fixed: 'right',
  },
];
export const getExcludeColumns: VxeGridPropTypes.Columns = [
  {
    title: '单据来源编号',
    field: 'orderNo',
    showOverflow: 'title',
    width: 130,
  },
  {
    title: '类型',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    width: 100,
  },

  {
    title: '金额(人民币)',
    field: 'totalAllPrice',
    showOverflow: 'title',
    slots: {
      footer: 'footer_totalAllPrice',
    },
    width: 100,
  },
  {
    title: '订单抽成金额',
    field: 'orderCommissionPrice',
    slots: {
      footer: 'footer_orderCommissionPrice',
    },
    showOverflow: 'title',
    width: 100,
  },

  {
    title: '接单人',
    field: 'receiverUserName',
    align: 'center',
    width: 100,
  },
  {
    title: '接单人抽成金额',
    field: 'receiverUserPrice',
    slots: {
      footer: 'footer_receiverUserPrice',
    },
    align: 'center',
    width: 100,
  },

  {
    title: '跟单人',
    field: 'merchandiserUserName',
    align: 'center',
    width: 100,
  },
  {
    title: '跟单人抽成金额',
    field: 'merchandiserUserPrice',
    slots: {
      footer: 'footer_merchandiserUserPrice',
    },
    align: 'center',
    width: 100,
  },

  {
    title: '业务经理',
    field: 'manageUserName',
    align: 'center',
    width: 70,
  },
  {
    title: '经理抽成',
    field: 'manageUserPrice',
    slots: {
      footer: 'footer_manageUserPrice',
    },
    align: 'center',
    width: 90,
  },
  {
    title: '项目组',
    field: 'xiangMuGroupName',
    align: 'center',
    width: 70,
  },
  {
    title: '项目组抽成',
    field: 'xiangMuGroupPrice',
    slots: {
      footer: 'footer_xiangMuGroupPrice',
    },
    align: 'center',
    width: 90,
  },
  {
    title: '操作人',
    field: 'userName',
    align: 'center',
    width: 70,
  },
  {
    width: 80,
    title: '操作',
    align: 'center',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

/**
 * 已抽成 表格列
 */
export const passTableColumns: VxeGridPropTypes.Columns = [
  {
    title: '收款/预收款编号',
    field: 'orderNo',
    showOverflow: 'title',
    // width: 130,
  },
  {
    title: '类型',
    field: 'type',
    showOverflow: 'title',
    align: 'center',
    // width: 100,
  },
  {
    title: '审批单号',
    field: 'approveNo',
    showOverflow: 'title',
    align: 'center',
    // width: 100,
  },
  {
    title: '操作人',
    field: 'receiverUserName',
    align: 'center',
    // width: 100,
  },
  {
    title: '操作时间',
    field: 'createTime',
    align: 'center',
    width: 140,
  },
];


export const passFormSchema: VxeFormItemProps[] = [
  {
    span: 5,
    field: 'orderNo',
    title: '收款单号',
    itemRender: {
      props: {
        placeholder: '收款/预收编号',
      },
      name: 'AInput',
    },
  },
  {
    span: 5,
    field: 'approveNo',
    title: '审批单号',
    itemRender: {
      props: {
        placeholder: '请输入审批单号',
      },
      name: 'AInput',
    },
  },
  {
    span: 5,
    itemRender: {
      name: 'VxeButtonGroup',
      options: [
        { type: 'reset', content: '重置' },
        { type: 'submit', content: '查询', status: 'primary' },
      ],
    },
  },
];


